<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of member
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Register extends MY_Controller {

    function register() {
        parent :: __construct();
        $this->load->model('pickup_model');
        $this->load->model('location_model');
        $this->load->model('member_model');
        $this->load->model('management_model');
        $this->load->model('settings_model');
    }

    function index() {
        
    }

//--Subha (Individual Registration)- 28/08/2012 */
    function new_member($mem_type=1) {
        $data['location']['state'] = $this->location_model->get_states(config_item('default_country_code'));

        if ($mem_type == 1) {
            $this->template->title('Welcome', 'carz.com')
                    ->set_partial('header', 'header/header')
                    ->set_partial('footer', 'footer/footer')
                    ->set_partial('customer_care', 'sidebar/customer_care')
                    ->set_partial('social_share', 'sidebar/social_share')
                    ->set_partial('search_reviews', 'sidebar/search_reviews')
                    ->set_partial('recent_news', 'sidebar/recent_news')
                    ->set_partial('recent_reviews', 'sidebar/recent_reviews')
                    ->build('pages/member/register', $data);
        }

        if ($mem_type == 2) {
            print "Dealer or Agent Registration (Pending)";
        }
    }

//--Subha (Registration-- SAVE)- 28/08/2012 */
    function submit($mem_type=1) {
        if ($mem_type == 1) {
            //print $mem_type;
            //die();
            $this->form_validation->set_rules('ind_fname', 'First Name', 'trim|required|alpha|min_length[3]');
            $this->form_validation->set_rules('ind_lname', 'Last Name', 'trim|required|alpha|min_length[2]');
            $this->form_validation->set_rules('ind_email', 'Email', 'trim|required|valid_email|is_unique[member_master.email]');
            $this->form_validation->set_rules('ind_cemail', 'Confirm Email', 'trim|required|valid_email|matches[ind_email]');
            $this->form_validation->set_rules('ind_areacode', 'Area Code', 'numeric');
            $this->form_validation->set_rules('ind_landline', 'Landline No', 'numeric');
            $this->form_validation->set_rules('ind_mobile', 'Mobile No', 'trim|required|numeric|min_length[10]|is_unique[member_master.mobile]');
            $this->form_validation->set_rules('state', 'State', 'trim|required|numeric');
            $this->form_validation->set_rules('city', 'City', 'trim|required|numeric');
            $this->form_validation->set_rules('car_agree', 'Agrrement', 'trim|required');

            if ($this->form_validation->run() == FALSE) {
                $msg = "Invalid Input !";
                $this->session->set_flashdata('message', $msg);
                redirect('member/register/new_member/1');
            } else {

                $post_data = array(
                    'type' => 1,
                    'first_name' => $this->input->post('ind_fname'),
                    'last_name' => $this->input->post('ind_lname'),
                    'email' => $this->input->post('ind_email'),
                    'area_code' => $this->input->post('ind_areacode'),
                    'landline' => $this->input->post('ind_landline'),
                    'mobile' => $this->input->post('ind_mobile'),
                    'country' => intval(config_item('default_country_code')),
                    'state' => $this->input->post('state'),
                    'city' => $this->input->post('city'),
                    'agree' => $this->input->post('car_agree'),
                    'password' => $this->commoncall->random_text(6),
                    'ip' => $this->commoncall->get_ip(),
                    'status' => 51,
                    'created_on' => date('Y-m-d H:m:s', now())
                );

                $msg = $this->member_model->append_member($post_data);
                $this->session->set_flashdata('message', $msg);
                redirect('member/register/new_member/1');
            }
        }
        if ($mem_type == 2) {
            
        }
    }

//--Profile Edit (01/09/2012) --//
    function edit($mem_type=1) {
        $id = intval($this->session->userdata('mem_id'));
        $data['member']['info'] = $this->member_model->get_member($id);
        $data['location']['state'] = $this->location_model->get_states(config_item('default_country_code'));


        if ($mem_type == 1) {
            $this->template->title('Welcome', 'carz.com')
                    ->set_partial('header', 'header/header')
                    ->set_partial('footer', 'footer/footer')
                    ->set_partial('customer_care', 'sidebar/customer_care')
                    ->set_partial('social_share', 'sidebar/social_share')
                    ->set_partial('search_reviews', 'sidebar/search_reviews')
                    ->set_partial('recent_news', 'sidebar/recent_news')
                    ->set_partial('recent_reviews', 'sidebar/recent_reviews')
                    ->build('pages/member/profile_edit', $data);
        }

        if ($mem_type == 2) {
            print "Dealer or Agent Registration (Pending)";
        }
    }

//--Profile Edit Submit --//
    function edit_submit($mem_type=1) {
        if ($mem_type == 1) {
            //print $mem_type;
            //die();
            $this->form_validation->set_rules('ind_fname', 'First Name', 'trim|required|alpha|min_length[3]');
            $this->form_validation->set_rules('ind_lname', 'Last Name', 'trim|required|alpha|min_length[2]');
            $this->form_validation->set_rules('ind_areacode', 'Area Code', 'numeric');
            $this->form_validation->set_rules('ind_landline', 'Landline No', 'numeric');
            $this->form_validation->set_rules('ind_mobile', 'Mobile No', 'trim|required|numeric|min_length[10]');
            $this->form_validation->set_rules('state', 'State', 'trim|required|numeric');
            $this->form_validation->set_rules('city', 'City', 'trim|required|numeric');

            if ($this->form_validation->run() == FALSE) {
                $msg = "Invalid Input !";
                $this->session->set_flashdata('message', $msg);
                redirect('member/register/edit/1');
            } else {

                $post_data = array(
                    'type' => 1,
                    'first_name' => $this->input->post('ind_fname'),
                    'last_name' => $this->input->post('ind_lname'),
                    'area_code' => $this->input->post('ind_areacode'),
                    'landline' => $this->input->post('ind_landline'),
                    'mobile' => $this->input->post('ind_mobile'),
                    'country' => intval(config_item('default_country_code')),
                    'state' => $this->input->post('state'),
                    'city' => $this->input->post('city'),
                );
                
                $this->db->where('id',intval($this->input->post('mem_id')));
                $this->db->update('member_master',$post_data);
                $msg = "Profile Updated !";
                $this->session->set_flashdata('message', $msg);
                redirect('member/myaccount');
            }
        }
        if ($mem_type == 2) {
            
        }
    }

}

?>
